using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class FacilityTypeList : admin_BaseUserControl
{
    FacilityTypeDAO daoFacType = new FacilityTypeDAO();
    public string GetState(object obj)
    {
        if ((bool)obj) return "Published";
        else return "Unpublished";
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        ActiveAccording = "facility";
        LoadData();    
    }
    public void LoadData()
    {
        string rq = "";
        if(Request["search"]!=null && Request["search"]!="") rq=Request["search"];
        dgrFacType.DataSource = daoFacType.GetAllFacilityTypes(rq);
        dgrFacType.DataBind();
    }
    protected void dgrFacType_RowEditing(object sender, GridViewEditEventArgs e)
    {
        //string id = dgrFacType.DataKeys[e.NewEditIndex].Value.ToString();
        //Response.Redirect("Default.aspx?ctrl=fac_type&mode=1&id=" + id);
        //dgrFacType.EditIndex = e.NewEditIndex;
        //LoadData();
    }
    protected void dgrFacType_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        //dgrFacType.EditIndex = -1;
       // LoadData();
    }
    protected void dgrFacType_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
       
    }


    protected void lnkDelete_Click(object sender, EventArgs e)
    {
        int count = 0;
        bool rs = true;
        foreach (GridViewRow row in dgrFacType.Rows)
        {
            bool check = ((CheckBox)(row.FindControl("chkChoice"))).Checked;
            if (check)
            {
                ((CheckBox)(row.FindControl("chkChoice"))).Checked = false;
                count++;
                int id = int.Parse(dgrFacType.DataKeys[row.RowIndex].Value.ToString());
                if (daoFacType.Delete(id) <= 0)
                {
                    rs = false;
                    break;
                }
            }
        }
        if (count == 0) ShowMessage("Please specify item to delete");
        else if (rs) ShowMessage("Selected items are deleted successfully");
        else ShowMessage("Error occured. Some items may not be deleted");
        LoadData();
    }
}
